package com.lineage.server.timecontroller.pc;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.thread.PcOtherThreadPool;
import com.lineage.server.world.WorldDragonKnight;
import java.util.Collection;
import java.util.Iterator;
import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MprTimerDragonKnight extends TimerTask {
  private static final Log _log = LogFactory.getLog(MprTimerDragonKnight.class);
  
  private ScheduledFuture<?> _timer;
  
  public void start() {
    int timeMillis = 1000;
    this._timer = PcOtherThreadPool.get().scheduleAtFixedRate(this, 1000L, 1000L);
  }
  
  public void run() {
    try {
      Collection<L1PcInstance> allPc = WorldDragonKnight.get().all();
      if (allPc.isEmpty())
        return; 
      Iterator<L1PcInstance> iter = allPc.iterator();
      while (iter.hasNext()) {
        L1PcInstance tgpc = iter.next();
        MprExecutor mpr = MprExecutor.get();
        if (mpr.check(tgpc)) {
          mpr.checkRegenMp(tgpc);
          Thread.sleep(1L);
        } 
      } 
    } catch (Exception e) {
      _log.error("Pc(龙骑) MP自然回复时间轴异常重启", e);
      PcOtherThreadPool.get().cancel(this._timer, false);
      MprTimerDragonKnight mprDragonKnight = new MprTimerDragonKnight();
      mprDragonKnight.start();
    } 
  }
}
